//
// UTF8.h
// libprotea
// Tools Library for the Protea Project / UTF-8 support
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

#ifndef __PROTEA_UTF8_H__
#define __PROTEA_UTF8_H__

class XCUNIPARSE {
public:
	XCUNIPARSE();
	void Reset();

	void AddUTF8Char( unsigned char character );
	void AddUTF16Char( unsigned short character );

	int OutputUTF8( unsigned char* destination, int size );
	int OutputUTF16( unsigned short* destination, int size );

	long unichars;
	long univalue;
};


// Whole string parsing
int UnicodeToUTF8( const wchar_t* source, char* dest, int len );
int UTF8ToUnicode( const char* source, wchar_t* dest, int len );

bool UTF8ToUTF8( const char* source, char* dest, int allocsize, int charsize );

// Single character parsing
bool UTF8ToUnicode( unsigned char value, XCUNIPARSE& parse );
int UnicodeToUTF8( const unsigned short source, char* dest );




// Xerces helpers
class __EXPORT UniTranslator
{
public:
	UniTranslator();
	UniTranslator( const unsigned short* value );
	UniTranslator( const char* value );
	~UniTranslator();

	const char* UTF8();
	const unsigned short* UTF16();


	UniTranslator& operator=(const char* s);

	UniTranslator& operator=(const unsigned short* value);


	operator const char*() { return UTF8(); };

	operator const unsigned short*() { return UTF16(); };



	void Clear();



private:
	bool utf8allocated;
	bool utf16allocated;

	char* utf8;
	unsigned short* utf16;
};


#endif

